package com.dragon.modules.yuegou.enums.code;

import com.dragon.common.constant.enums.IBusinessCode;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 会员业务状态码
 * 
 * @author 刘武
 *
 */
public enum OrderCode implements IBusinessCode {

	ALREADY_PAID(16000, "订单已支付，不能再次支付"),
	ALREADY_CLOSED(16001, "订单已关闭，不能支付"),
	ALREADY_SUCCEED(16002, "订单已完成，不能再次支付"),
	ALREADY_EXPIRED(16003, "订单已超时，不能再次支付"),
	INVALID_PAY_AMOUNT(16004, "非法支付金额，与订单应付金额不符"),
	SKU_STOCK_LIMIT(16005, "商品库存不足"),
	SKU_PURCHASE_LIMIT(16006, "%s商品限购"),
	MERCHANT_NE(16007, "核销失败，该订单属于其他商户"),
	ORDERVERIFY_STATUS_NOT_NORMAL(16008, "核销失败，订单状态异常"),
	ORDER_CANCEL(16009, "订单取消失败"),
	CART_SKU_EMPTY(16010, "找不到商品"),
	ORDER_STATUS_ERROR(16011, "只有未支付订单才能支付"),
	ORDER_STATUS_PICKUPSTARTTIME(16012, "未到达核销时间"),
	ORDER_STATUS_PICKUPEXPIRETIME(16013, "超过核销时间"),
	ORDER_STATUS_REPEAT(16014, "重复核销"),
	ORDER_SATSUS_ERROR(16015, "订单状态错误，不能支付"),
	ORDER_TYPE_ERROR(16016, "订单类型错误，不能支付"),
	SPU_OVERDUE(16017, "商品已过期，不能购买"),
	SPU_OFFSALE(16018, "商品已下架，不能购买"),
	SPU_NOTSALE(16019, "商品未起售，不能购买"),
	ALREADY_REFUND(16020, "订单已退款，不能再次退款"),
	CANNOT_REFUND(16021, "订单没达到退款条件，无法退款"),
	SPU_PURCHASE_LIMIT(16022, "%s商品限购"),
	GOODS_CANNOT_REFUND(16023, "单品已退款，不能重复退款"),
	AMOUNT_IS_LESS(16024, "退款金额必须是一个正数"),
	MEAL_CANNOT_REFUND(16025, "套餐商品不能退款"),
	FEE_TOO_BIG(16026, "退款金额过大，无法退款"),
	STATUS_ERROR(16027, "派送订单列表查询，订单类型传入错误"),
	PAID_WAITPOST(16028, "已支付订单才能接单"),
	PAID_CLOSED(16029, "已支付订单才能拒单"),
	WAITPOST_SHIPPING(16030, "待配送订单才能配送(送达)"),
	SHIPPING_SUCCEED(16031, "配送中订单不能确认收货"),
	ORDER_REFUSAL_FAIL(16032, "配送中订单不能确认收货%s"),
	ORDER_REFUND_STATUS_ERROR(16033, "待接单订单才能退款"),
	REFUSE_ORDER_STATUS_ERROR(16034, "待接单订单才能拒绝接单"),
	REFUSE_ORDER_TYPE_ERROR(16035, "到家服务订单才能拒绝接单"),
	REFUSE_ORDER_PAYMETHOD_ERROR(16036, "微信支付宝支付订单才能拒绝接单"),
	CONSIGNEE_NAME_IS_NOT_EMPTY(16037, "收货人姓名不能为空"),
	CONSIGNEE_MOBILE_INCORRECT_FORMAT(16038, "收货人电话格式不正确"),
	CREATED_OTHOR_ORDER_ERROR(16039, "创建第三方订单错误"),
	ORDER_CLOSE(16040, "订单已关闭"),
	
	ORDER_COUPON_TEMPLATE_ERROR(16041, "订单只能用一种券抵扣"),
	ORDER_COUPON_USER_ERROR(16042, "订单优惠券选择错误"),
	ORDER_COUPON_DITTO_ERROR(16043, "优惠券不允许叠加使用"),
	SPU_UPPER(16044, "商品已上架，不能发放"),
	ORDER_IS_REFUND(16045, "订单已退款，无法核销"),
	JD_SKU_REFUND(16046, "存在已退款的商品"),
	ORDER_FEE_ERROR(16047, "已达到领取上限，不能再领取了哦"),
	MEMBER_ORDER_EXIST(16048, "您的操作过于频繁"),
	MERCHANT_NOT_EXIST(16049, "没有可核销商户");
	private final Integer code;

	private final String message;

	private OrderCode(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public Integer getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	/**
	 * 把code转化为ResponseCode枚举
	 * 
	 * @param code 代码
	 * @return
	 */
	public static OrderCode from(Integer code) {
		if (code == null) {
			return null;
		}
		return CODE_MAP.get(code);
	}

	/**
	 * Code Map for ResponseCode
	 */
	private static final Map<Integer, OrderCode> CODE_MAP = Stream.of(OrderCode.values())
			.collect(Collectors.toMap(OrderCode::getCode, e -> e));
	
}
